package com.walkline.travelassistant.dao;

import org.json.me.JSONObject;

import com.walkline.travelassistant.TravelAssistantException;
import com.walkline.travelassistant.TravelAssistantSDK;
import com.walkline.travelassistant.inf.Direction;
import com.walkline.travelassistant.inf.RouteWrapper;
import com.walkline.travelassistant.inf.Taxi;
import com.walkline.util.Function;

public class TravelAssistantDirection extends TravelAssistantObject implements Direction
{
	private int _status = 0;
	private String _message = "";
	private int _type = 0;
	private RouteWrapper _routes = null;
	private Taxi _taxi = null;

	public TravelAssistantDirection(TravelAssistantSDK travelAssistant, JSONObject jsonObject) throws TravelAssistantException
	{
		super(travelAssistant, jsonObject);

		JSONObject directionObject = jsonObject;
		if (directionObject != null)
		{
			_status = directionObject.optInt("status");
			_message = directionObject.optString("message");
			_type = directionObject.optInt("type");

			if (_type != 2)
			{
				Function.errorDialog("请重新选择起/始地点！");
				return;
			}

			JSONObject result = directionObject.optJSONObject("result");
			if (result != null)
			{
				_routes = new TravelAssistantRouteWrapper(travelAssistant, result);

				if (!result.isNull("taxi")) {_taxi = new TravelAssistantTaxi(travelAssistant, result.optJSONObject("taxi"));}
			}
		}
	}

	public int getStatus() {return _status;}

	public String getMessage() {return _message;}

	public int getType() {return _type;}

	public RouteWrapper getRoutes() {return _routes;}

	public Taxi getTaxi() {return _taxi;}
}